Public Partial Class FrmListaSolicitudModificar
    Inherits System.Web.UI.Page
    Private TblCliente As CapaDeNegocios.nCliente = New CapaDeNegocios.nCliente
    Private TblSolicitud As CapaDeNegocios.nSolicitudServicio = New CapaDeNegocios.nSolicitudServicio
    Dim IdSolicitudInterno As String
    Dim IdClienteInterno As String


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("Login") = "Anonimo" Then
            Response.Redirect("/")
        End If

        Dim IdSolicitudInterno As String
        Dim IdClienteInterno As String
        IdSolicitudInterno = Request.QueryString("IdSolicitud")
        IdClienteInterno = Request.QueryString("IdCliente")
        If Not Page.IsPostBack Then
            IdSolicitudInterno = Request.QueryString("IdSolicitud")
            IdClienteInterno = Request.QueryString("IdCliente")
            llenarCboClientes()
            llenarGVSolicitudes()
            lnkReporteSolicitudes.Visible = False
            lnkReporteSolicitudes.OnClientClick = "javascript:var popup = window.open('Reportes/RptSolicitudServiciosModificar.aspx',(new Date().getTime()),'Width=900,Height=500,Scrollbars=NO,Resizable=NO,Location=NO,Menubar=NO,Status=NO,Titlebar=NO,Toolbar=NO')"
        End If
    End Sub
    Sub llenarCboClientes()
        CboClientes.DataSource = TblCliente.Listar("", "", "", "", "", "", "", "", "", "", "", "")
        CboClientes.DataTextField = ("RazonSocial")
        CboClientes.DataValueField = ("CodigoCliente")
        CboClientes.DataBind()
    End Sub
    Sub llenarGVSolicitudes()

        If CboClientes.SelectedValue <> "" Then
            If CboEstado.SelectedValue <> "" Then
                GVSolicitudes.SelectedIndex = -1
                GVSolicitudes.DataSource = New DataSet

                lnkReporteSolicitudes.Visible = True
                GVSolicitudes.DataSource = TblSolicitud.BuscarFiltrado(0, (New Date), (New Date), "", CboClientes.SelectedValue, CboEstado.SelectedValue, 0)
                Session("ReporteSolicitudes") = GVSolicitudes.DataSource
                GVSolicitudes.DataBind()
                GVSolicitudes.SelectedIndex = -1
            End If
        End If
    End Sub

    Protected Sub GVSolicitudes_RowCommand(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GVSolicitudes.RowCommand
        Dim dts As DataSet = New DataSet
        Dim CodigoSolicitud As Double
        Dim Estado As String
        Dim codigoTunidad As Integer
        If e.CommandName = "Select" Then
            CodigoSolicitud = e.CommandSource.Parent.FindControl("LblNumeroSolicitud").text
            codigoTunidad = e.CommandSource.Parent.FindControl("HFCodigoTunidad").value
            Estado = TblSolicitud.Buscar(CodigoSolicitud, "", "", "", "", "", "").Tables(0).Rows(0)("EstadoSolicitud")
            'If (Estado <> "suspendida") Or (Estado <> "Cumplida") Then
            TblSolicitud.Modificar(CodigoSolicitud, New Date, New Date, "", 0, "Suspendida", codigoTunidad)

            'End If
        End If
        llenarGVSolicitudes()
    End Sub

    Protected Sub CboClientes_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CboClientes.SelectedIndexChanged
        llenarGVSolicitudes()
        If CboClientes.SelectedValue = "" Then
            lnkReporteSolicitudes.Visible = False
        End If
    End Sub

    Protected Sub CboEstado_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CboEstado.SelectedIndexChanged
        llenarGVSolicitudes()
    End Sub

    Protected Sub GVSolicitudes_RowDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GVSolicitudes.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim IntLnkSeleccion As LinkButton = e.Row.FindControl("lnkSuspender")
            IntLnkSeleccion.Visible = (CboEstado.SelectedValue = "Pendiente")
        End If

    End Sub
End Class